package com.koron.css2.newProjectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjPubUpDealings;
import com.koron.css2.newProjectCenter.bean.query.PjPubUpDealingsQuery;
import com.koron.css2.newProjectCenter.mapper.PjPubUpDealingsMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;

/**
 * @Author: 苏小龙
 * @CreateTime: 2024-12-03
 * @Description: 往来单位
 * @Version: 1.0
 */
public class PjPubUpDealingsList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPubUpDealingsQuery pubUpInvoiceQuery = JsonUtils.objectToPojo(req.getData(), PjPubUpDealingsQuery.class);
            PjPubUpDealingsMapper pjPubUpInvoiceMapper= factory.getMapper(PjPubUpDealingsMapper.class);

            PageHelper.startPage(pubUpInvoiceQuery.getPage(), pubUpInvoiceQuery.getPageCount());

            Map<String, String> PIS = Tools.mapDicByCode(factory, "DWLX");

            List<PjPubUpDealings> pubUpInvoiceList = pjPubUpInvoiceMapper.getList(pubUpInvoiceQuery);
            // pubUpInvoiceList.stream().forEach(s->{
            //     s.setUnitType(PIS.get(s.getUnitType()));
            // });

            MessageBean<PageInfo> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "往来单位表分页查询成功", PageInfo.class);
            messageBean.setData(new PageInfo<>(pubUpInvoiceList));
            return messageBean;
        } catch (Exception e) {
            logger.error("往来单位表分页查询失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "往来单位表分页查询失败:", null);
        }
    }
}
